package com.shushan.pages.newtype.bean;

import com.android.net.bean.NetBaseBean;
import com.shushan.base.Constants;
import com.shushan.pages.bean.SubjectSyncExerciseBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: EnglishWordsExerciseEntryBean
 * @Desciption: //单词练习入口页数据bean
 * @author: zhangshihao
 * @date: 2018-07-31
 */
public class EnglishWordsExerciseEntryBean extends NetBaseBean {

    private List<EnglishWordsEntryItemBean> entryItemBeans = new ArrayList<>();

    public SubjectSyncExerciseBean englishExerciseBean;

    public int paper_id;
    public int progress_lock;
    public int score;
    public int time;

    @Override
    public void initByJson(JSONObject jsonObject) throws JSONException {
        if(jsonObject == null){
            return;
        }
        JSONArray entryItemArr = jsonObject.optJSONArray("word");
        if(entryItemArr != null && entryItemArr.length() > 0){
            for(int i=0;i<entryItemArr.length();i++){
                JSONObject entryItemObj = entryItemArr.optJSONObject(i);
                EnglishWordsEntryItemBean itemBean = new EnglishWordsEntryItemBean();
                itemBean.initByJson(entryItemObj);
                entryItemBeans.add(itemBean);
            }
        }

        JSONObject subjectObj = jsonObject.optJSONObject("subject");
        JSONObject englishObj = subjectObj.optJSONObject(Constants.SUBJECT_ENGLISH_ID+"");
        if(englishObj != null){
            englishExerciseBean = new SubjectSyncExerciseBean();
            englishExerciseBean.initByJson(englishObj);
        }

        paper_id = jsonObject.optInt("paper_id",0);
        progress_lock = jsonObject.optInt("progress_lock",0);

        JSONObject rewardObj = jsonObject.optJSONObject("reward");
        if(rewardObj != null){
            score = rewardObj.optInt("score",0);
            time = rewardObj.optInt("time",0);
        }
    }

    public List<EnglishWordsEntryItemBean> getEntryItemBeans() {
        return entryItemBeans;
    }

}
